#! /bin/sh
#
# susan       This shell script takes care of starting and stopping
#	       the susan Storage daemon.
#
# chkconfig: 2345 90 99
# description: Backup Archiving REcovery Open Sourced.
#
#

# Source function library
. /etc/rc.d/functions.susan

case "$1" in
    start)
	[ -x ${BACSDBIN}/susan-sd ] && {
	    sleep 2
	    echo -n "Starting the Storage daemon: "
	    OPTIONS=''
	    if [ "${SD_USER}" != '' ]; then
	       OPTIONS="${OPTIONS} -u ${SD_USER}"
	    fi

	    if [ "${SD_GROUP}" != '' ]; then
	       OPTIONS="${OPTIONS} -g ${SD_GROUP}"
	    fi

	    ${BACSDBIN}/susan-sd $2 ${OPTIONS} -v -c ${BACSDCFG}/susan-sd.conf
	    echo Done.
	}
	;;
    stop)
	[ -x ${BACSDBIN}/susan-sd ] && {
	    echo -n "Stopping the Storage daemon: "
	    killproc ${BACSDBIN}/susan-sd ${SD_PORT}
	    echo Done.
	}
	;;
    restart)
	$0 stop
	sleep 5
	$0 start
	;;
    status)
	[ -x ${BACSDBIN}/susan-sd ] && status ${BACSDBIN}/susan-sd ${SD_PORT}
	;;
    *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
	;;
esac
exit 0
